﻿@using OBUCare.Core.Models;
@using OBUCare.Core.Models;
@using OBUCare.Web.Models;
@using OBUCare.Web.Infrastructure;
@model REPAIR_ORDERS
@{
    ViewBag.Title = "标签维修单";
    string id = string.Empty;
    ObuInfo info = ViewBag.ObuInfo;
    string faultType = ViewBag.FaultType;
    bool faceStatus = ViewBag.FaceStatus;
    var faultModel = ViewBag.FaultViewModel as IEnumerable<ExtendedSelectListItem<DICT_TYPE_VALUE>>;
    int repairType = -1;
    string repairTypeTxt = string.Empty;
    string faultTxt = ViewBag.FaultTxt;
    string spare_obu_issue_date = string.Empty;
    string spare_obu_price = string.Empty;
    string spare_obu_no = string.Empty;
    string agentNo = string.Empty;
    var dateNow = DateTime.Now.ToString("yyyy-MM-dd");
    if (Model != null)
    {
        repairType = Model.REPAIR_TYPE;
        faceStatus = Model.FACE_STATUS;
        id = Model.OBU_NO.ToString();
        repairTypeTxt = Model.REPAIRED_COMMENT;
        spare_obu_issue_date = Model.SPARE_OBU_ISSUE_DATE.ToString();
        spare_obu_price = Model.SPARE_OBU_PRICE.ToString();
        spare_obu_no = Model.SPARE_OBU_NO;
        agentNo = Model.AGENT_NO;
    }
    ObuDropDownListHlper ddlHelper = new ObuDropDownListHlper();
    var operatorInfo = UIUtility.GetCurrentUser();

    var menuNames = UIUtility.getMenuName(Request.RawUrl);

    string AgentNo = UIUtility.getAgentByModule(operatorInfo, menuNames.ToString());
}
<h2>
    <font color="#4fb82c" class="txt14_24">标签维修单编辑&gt;&gt;</font></h2>
@using (Html.BeginForm())
{
    @Html.ValidationSummary(true)
    @Html.Hidden("AgentNo", @AgentNo)
    <div id="divObuContainer">
        <br />
        <img src="@Url.Content("~/Content/images/blueline1.png")" width="805" height="21">
        <br />
        <center>
            <h1>
                基本信息</h1>
        </center>
        <br />
        <span style="display: inline">@Html.TextBox("IDs", @id, new { width = "0px" })</span>
        <img src="@Url.Content("~/Content/images/blueline1.png")" width="805" height="21">
        <br />
        <!--动态加载标签基本信息的div容器-->
        <div id="divObubaseInfoContainer" style="width: 100%">
            @Html.Partial("ObuBaseInfoControl", info)
        </div>
        <div>
            <table>
                <tr>
                    <td width="20%">
                    </td>
                    <td width="30%">
                    </td>
                    <td width="20%">
                    </td>
                    <td width="30%" align="right">
                    </td>
                </tr>
                <tr>
                    <td>
                        @Html.LabelFor(model => model.MOBILE_TEL_NO)
                    </td>
                    <td>
                        @Html.EditorFor(model => model.MOBILE_TEL_NO)&nbsp<span style="color: Red;">*</span>
                        @Html.ValidationMessageFor(model => model.MOBILE_TEL_NO)
                    </td>
                    <td>
                        @Html.LabelFor(model => model.TEL_NO)
                    </td>
                    <td>
                        @Html.EditorFor(model => model.TEL_NO)
                        @Html.ValidationMessageFor(model => model.TEL_NO)
                    </td>
                </tr>
                <tr>
                    <td>
                        @Html.LabelFor(model => model.MAX_PRICE)
                    </td>
                    <td>
                        @Html.EditorFor(model => model.MAX_PRICE)&nbsp<span style="color: Red;">*</span>
                        @Html.ValidationMessageFor(model => model.MAX_PRICE)
                    </td>
                    <td>
                        @Html.LabelFor(model => model.REPORTER)
                    </td>
                    <td>
                        @Html.EditorFor(model => model.REPORTER)&nbsp<span style="color: Red;">*</span>
                        @Html.ValidationMessageFor(model => model.REPORTER)
                    </td>
                </tr>
                <tr>
                    <td colspan="4">
                        <img src="@Url.Content("~/Content/images/blueline1.png")" width="805" height="21">
                    </td>
                </tr>
                <tr>
                    <td>
                        @Html.Label("lblOrderFalut", "故障描述")
                        @* @Html.LabelFor(model => model.OrderFalut)
                        @Html.ValidationMessageFor(model => model.OrderFalut)*@ @*@Html.HiddenFor(model => model.OrderFalut, new { width = "0px" })*@
                    </td>
                    <td colspan="3">
                        @Html.Partial("_FaultCheckBoxList", faultModel)
                    </td>
                </tr>
                <tr>
                    <td colspan="4">
                        <img src="@Url.Content("~/Content/images/blueline1.png")" width="805" height="21">
                    </td>
                </tr>
                <tr>
                    <td>
                        @Html.LabelFor(model => model.FACE_STATUS)
                    </td>
                    <td colspan="3">
                        @Html.RadioButtonFor(model => model.FACE_STATUS, false, new { @id = "FACE_STATUS0" })
                        @Html.Label("FACE_STATUS0", "外观完好")
                        @Html.RadioButtonFor(model => model.FACE_STATUS, true, new { @id = "FACE_STATUS1", @checked = "checked" })
                        @Html.Label("FACE_STATUS1", "外观有故障")
                        @Html.ValidationMessageFor(model => model.FACE_STATUS)
                    </td>
                </tr>
                <tr>
                    <td colspan="4">
                        <img src="@Url.Content("~/Content/images/blueline1.png")" width="805" height="21">
                    </td>
                </tr>
                <tr>
                    <td>
                        @Html.LabelFor(model => model.REPAIR_TYPE)
                    </td>
                    <td colspan="3">
                        @*@Html.EditorFor(model => model.REPAIR_TYPE)*@
                        @Html.Partial("_RepairType", ViewBag.RepairTypeViewModel as IEnumerable<ExtendedSelectListItem<REPAIR_TYPE>>)
                        @Html.ValidationMessageFor(model => model.REPAIR_TYPE)
                    </td>
                </tr>
                <tr>
                    <td colspan="4">
                        <img src="@Url.Content("~/Content/images/blueline1.png")" width="805" height="21">
                    </td>
                </tr>
                <tr>
                    <td>
                        @Html.Label("isNeedSpareObu", "是否需要备用标签:")
                    </td>
                    <td colspan="3">
                        @Html.RadioButton("radisNeedSpareObu", "1", new { @id = "radisNeedSpareObuY" })
                        @Html.Label("radisNeedSpareObuY", "是")
                        @Html.RadioButton("radisNeedSpareObu", "0", true, new { @id = "radisNeedSpareObuN" })
                        @Html.Label("radisNeedSpareObuY", "否")
                    </td>
                </tr>
                <tr>
                    <td colspan="4">
                        <table id="tbSpare" style="display: none">
                            <tr>
                                <td colspan="4">
                                    <img src="@Url.Content("~/Content/images/blueline1.png")" width="805" height="21">
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    @Html.LabelFor(model => model.SPARE_OBU_NO)
                                </td>
                                <td>
                                    @Html.EditorFor(model => model.SPARE_OBU_NO)
                                    @Html.ValidationMessageFor(model => model.SPARE_OBU_NO)
                                </td>
                                <td>
                                    @Html.LabelFor(model => model.SPARE_OBU_PRICE)
                                </td>
                                <td>
                                    @Html.DisplayFor(model => model.SPARE_OBU_PRICE) (元)
                                    @*@Html.ValidationMessageFor(model => model.SPARE_OBU_PRICE)*@
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    @Html.LabelFor(model => model.SPARE_OBU_ISSUE_DATE)
                                </td>
                                <td>
                                    @if (Model == null)
                                    {
                                        @Html.Telerik().DatePickerFor(m => m.SPARE_OBU_ISSUE_DATE).Value(DateTime.Now.ToShortDateString()).OpenOnFocus(true).ShowButton(false).Format(UIConstants.DateFormatString)
                                    }
                                    else
                                    {
                                        @Html.Telerik().DatePicker().Name("SPARE_OBU_ISSUE_DATE_UI").Value(Model.SPARE_OBU_ISSUE_DATE).OpenOnFocus(true).ShowButton(false).Format(UIConstants.DateFormatString)
                                    }
                                        &nbsp<span
                                style="color: Red;">*</span>
                                            @Html.HiddenFor(model => model.SPARE_OBU_ISSUE_DATE)
                                    @if (Model == null)
                                    {
                                     @Html.ValidationMessageFor(model => model.SPARE_OBU_ISSUE_DATE)
                                    }
                                    else
                                    {
                                     @Html.ValidationMessage("SPARE_OBU_ISSUE_DATE_UI") 
                                    }

                                </td>
                                <td>
                                </td>
                                <td>
                                </td>
                            </tr>
                        </table>
                    </td>
                </tr>
                <tr>
                    <td colspan="4">
                        <img src="@Url.Content("~/Content/images/blueline1.png")" width="805" height="21">
                    </td>
                </tr>
                <tr>
                    <td>
                        @Html.LabelFor(model => model.REPORT_DATE)
                    </td>
                    <td>
                         @if (Model == null)
                         {
                        @Html.Telerik().DatePickerFor(model => model.REPORT_DATE).Value(DateTime.Now.ToShortDateString()).OpenOnFocus(true).ShowButton(false).Format(UIConstants.DateFormatString)
                         }
                         else
                         {
                        @Html.Telerik().DatePicker().Name("REPORT_DATE_UI").Value(Model.REPORT_DATE).OpenOnFocus(true).ShowButton(false).Format(UIConstants.DateFormatString)
                         }
                                        
                        &nbsp<span
                            style="color: Red;">*</span>
                        @Html.HiddenFor(model => model.REPORT_DATE)
                        @if (Model == null)
                        {
                        @Html.ValidationMessageFor(model => model.REPORT_DATE)
                        }
                        else
                        {
                        @Html.ValidationMessage("REPORT_DATE_UI")                                                                    
                        }
                    </td>
                    <td>
                    </td>
                    <td>
                    </td>
                </tr>
            </table>
        </div>
        <br />
        <img src="@Url.Content("~/Content/images/blueline1.png")" width="805" height="21">
        <br />
        <div>
            <input type="submit" id="submit" value=" " style="background-image: url(@Url.Content("~/Content/images/button_up.gif")); width:200;height:30" />
        
            <input type="button" onclick="window.open('/RepairOrders/Print/@Model.ID')" value="打印" />        
        </div>
    </div>
}
<script type="text/javascript">
    $(function () {
        var drop = $('#Agent').data('tDropDownList'); 
        if(!"@agentNo".StringIsNullOrEmpty()){
            $.post("/RepairOrders/_GetAgentReturnIndex",{AgentNo:"@agentNo"},function(data){
//            alert(data.Index);
            drop.select(data.Index);
            })
        }

        var faults = "@faultType".split(',');
        for (var i = 0; i < faults.length; i++) {
            $("#orderFault" + faults[i]).attr("checked", "checked");
        }
        $("#orderFaultReMark").val("@faultTxt");
        $("#REPAIRED_COMMENT").val("@repairTypeTxt");
        if ("@faceStatus" == "False") {
            $("#FACE_STATUS0").attr("checked", "checked");
        }
        else {
            $("#FACE_STATUS1").attr("checked", "checked");
        }

        var d = $("#CheckDate").attr("Date");
            $("#REPAIR_TYPE"+@repairType).attr("checked", "checked");
//         如果有备签 则不允许修改是否有备签
        if ("@spare_obu_no".length != 0 || "@spare_obu_price".length != 0) {
            $("#tbSpare").attr("style", "display:inline");
            $("#radisNeedSpareObuY").attr("checked","checked");
            document.getElementById("radisNeedSpareObuN").disabled=true;
        }
        else
        {
          document.getElementById("radisNeedSpareObuN").disabled=true;
          document.getElementById("radisNeedSpareObuY").disabled=true;
        }
        $("#radisNeedSpareObuN").click(function () {
            $("#SPARE_OBU_ISSUE_DATE_UI").val("");
            $("#SPARE_OBU_PRICE").val("");
             $("#SPARE_OBU_NO").val("");
            $("#tbSpare").attr("style", "display:none");
        })
        $("#radisNeedSpareObuY").click(function () {
            $("#SPARE_OBU_ISSUE_DATE_UI").val("@dateNow");
            $("#SPARE_OBU_PRICE").val("300");
            $("#tbSpare").attr("style", "display:inline");
        })

        $("#submit").click(function () {
            var reportDate=$('#REPORT_DATE_UI').val();
            if($.trim(reportDate).length==0)
            {
               alert("请输入受理日期");return false;
            }
            var chk = $("#radisNeedSpareObuY").attr("checked");
            if (chk == "checked") {
                var s_obu_no = $("#SPARE_OBU_NO").val();
                var s_obu_price = $("#SPARE_OBU_PRICE").val()
                var s_obu_issue_date = $("#SPARE_OBU_ISSUE_DATE_UI").val();
                 if (s_obu_price.length == 0) {
                    alert("请输入备用标签押金！"); return false;
                }
                else if (s_obu_issue_date.length == 0) {
                    alert("请输入备用标签安装日期！"); return false;
                }
            }
        })

    });
    function getDate(separator) {
        var d, s = "";
        d = new Date();
        s += d.getFullYear() + separator;
        s += (d.getMonth() + 1) + separator;
        s += d.getDate();
        return s;
    }

</script>
@section Scripts {
    @Scripts.Render("~/bundles/jqueryval")
}
